package org.example.ioc;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
@Slf4j
class IocRunner implements CommandLineRunner {

    @Resource
    private ServiceA serviceA1;

    @Resource
    private ServiceA serviceA2;

    @Resource
    private ServiceA serviceA3;

    @Resource
    private ServiceA serviceA4;

    @Resource
    private ServiceB serviceB1;

    @Resource
    private ServiceB serviceB2;

    @Override
    public void run(String... args) throws Exception {
        dumpServiceA(1, serviceA1);
        dumpServiceA(2, serviceA2);
        dumpServiceA(3, serviceA3);
        dumpServiceA(4, serviceA4);
        dumpServiceB(1, serviceB1);
        dumpServiceB(2, serviceB2);
    }

    private void dumpServiceA(int i, ServiceA serviceA) {
        ServiceB serviceB = serviceA.getServiceB();
        log.info("serviceA{}: {} -> {}", i, serviceA.getName(), serviceB.getName());
    }

    private void dumpServiceB(int i, ServiceB serviceB) {
        log.info("serviceB{}: {}", i, serviceB.getName());
    }
}
